home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr48 / pas_0593.zip / TEXTSEEK.PAS < prev    next >
Pascal/Delphi Source File  |  1993-05-30  |  2KB  |  61 lines

  1. {─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
  2. Msg  : 349 of 412
  3. From : Marco Miltenburg                    2:512/169.0          14 May 93  09:44
  4. To   : Raphael Vanney                      2:320/7.0
  5. Subj : Pardon if repeat
  6. ────────────────────────────────────────────────────────────────────────────────
  7.  Hi Rapael,
  8.  
  9.  > One cannot seek in a text file...
  10.  
  11.     Sure you can... For DOS, textfiles are really the same things as typed
  12. files, so why don't ask DOS ;-) ?  Try this one. F is a textfile and n is the
  13. file-offset.}
  14.  
  15. Procedure tSeek(Var f:Text; n:LongInt); Assembler;
  16. Asm
  17.     push  DS
  18.     push  BP
  19.  
  20.     lds   SI,f
  21.     lodsw                            { handle }
  22.     mov   BX,AX
  23.  
  24.     mov   CX, word ptr [BP+8]
  25.     mov   DX, word ptr [BP+6]
  26.  
  27.     mov   AX,4200h              {AL = 2, AH = 42}
  28.     int   21h
  29.  
  30.     les   DI,f
  31.     mov   AX,DI
  32.     add   AX,8
  33.     mov   DI,AX
  34.  
  35.     lodsw                            { mode }
  36.     lodsw                            { bufsize }
  37.     mov   CX,AX                      { CX = number of bytes to read }
  38.     lodsw                            { private }
  39.     lodsw                            { bufpos  }
  40.     lodsw                            { bufend  }
  41.     lodsw                            { offset of pointer to textbuf }
  42.     mov   DX,AX                      { DX = offset of textbuf }
  43.     lodsw
  44.     mov   DS,AX                      { DS = segment of textbuf }
  45.     mov   AH,3Fh
  46.     int   21h
  47.     push  AX                         { Save AX on stack }
  48.  
  49.     les   DI,f                       { ES:DI points to f }
  50.     mov   AX,DI                      { Move pointer to position 8 }
  51.     add   AX,8
  52.     mov   DI,AX
  53.  
  54.     mov   AX,0                       { Bufpos = 0 }
  55.     stosw
  56.     pop   AX                         { Bufend = number of bytes read }
  57.     stosw
  58.  
  59.     pop   BP
  60.     pop   DS
  61. End; { tSeek }